bitkeeper revision 1.990.2.4 (40d6e58cfM0ifkkM2ZVDB4SR04_JmQ)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Mon, 21 Jun 2004 13:41:32 +0000 (13:41 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Mon, 21 Jun 2004 13:41:32 +0000 (13:41 +0000)
Change to using a different variable for the global opts.
Change some command names and options.

tools/xenmgr/lib/xm/create.py
tools/xenmgr/lib/xm/main.py
tools/xenmgr/lib/xm/opts.py
tools/xenmgr/lib/xm/shutdown.py

index 863227ad4cbfb78c6e1fd1e761a48b51db959b80..3843007a10748f327aac67e2430e1064da6c411d 100644 (file)
@@ -7,28 +7,28 @@ from xenmgr.XendClient import server
 
 from xenmgr.xm.opts import *
 
-opts = Opts(use="""[options]
+gopts = Opts(use="""[options]
 
 Create a domain.
 """)
 
-opts.opt('help', short='h',
+gopts.opt('help', short='h',
          fn=set_value, default=0,
          use="Print this help.")
 
-opts.opt('quiet', short='q',
+gopts.opt('quiet', short='q',
          fn=set_true, default=0,
          use="Quiet.")
 
-opts.opt('path', val='PATH',
+gopts.opt('path', val='PATH',
          fn=set_value, default='.:/etc/xc',
          use="Search path for default scripts.")
 
-opts.opt('defaults', short='f', val='FILE',
+gopts.opt('defaults', short='f', val='FILE',
          fn=set_value, default='xmdefaults',
          use="Use the given default script.")
 
-opts.opt('config', short='F', val='FILE',
+gopts.opt('config', short='F', val='FILE',
          fn=set_value, default=None,
          use='Domain configuration to use.')
 
@@ -38,102 +38,103 @@ def set_var(opt, k, v):
         (k, v) = string.split(d, '=')
         opt.opts.setvar(k, v)
 
-opts.opt('define', short='D', val='VAR=VAL',
+gopts.opt('define', short='D', val='VAR=VAL',
          fn=set_var, default=None,
          use="""Set variables before loading defaults, e.g. '-D vmid=3;ip=1.2.3.4'
          to set vmid and ip.""")
 
-opts.opt('dryrun', short='n',
+gopts.opt('dryrun', short='n',
          fn=set_true, default=0,
          use="Dry run - print the config but don't create the domain.")
 
-opts.opt('console', short='c',
+gopts.opt('console', short='c',
          fn=set_true, default=0,
          use="Connect to console after domain is created.")
 
-opts.opt('kernel', short='k', val='FILE',
+gopts.opt('kernel', short='k', val='FILE',
+         fn=set_value, default=None,
          use="Path to kernel image.")
 
-opts.opt('ramdisk', short='r', val='FILE',
+gopts.opt('ramdisk', short='r', val='FILE',
          fn=set_value, default='',
          use="Path to ramdisk.")
 
-opts.opt('builder', short='b', val='FUNCTION',
+gopts.opt('builder', short='b', val='FUNCTION',
          fn=set_value, default='linux',
          use="Function to use to build the domain.")
 
-opts.opt('memory', short='m', val='MEMORY',
+gopts.opt('memory', short='m', val='MEMORY',
          fn=set_value, default=128,
          use="Domain memory in MB.")
 
-opts.opt('disk', short='d', val='phy:DEV,VDEV,MODE',
+gopts.opt('disk', short='d', val='phy:DEV,VDEV,MODE',
          fn=append_value, default=[],
          use="""Add a disk device to a domain. The physical device is DEV, which
          is exported to the domain as VDEV. The disk is read-only if MODE is r,
          read-write if mode is 'w'.""")
 
-opts.opt('pci', val='BUS,DEV,FUNC',
+gopts.opt('pci', val='BUS,DEV,FUNC',
          fn=append_value, default=[],
-         use="""Add a PCI device to a domain.""")
+         use="""Add a PCI device to a domain, using given params (in hex).""")
 
-opts.opt('ipaddr', short='i', val="IPADDR",
+gopts.opt('ipaddr', short='i', val="IPADDR",
          fn=append_value, default=[],
          use="Add an IP address to the domain.")
 
-opts.opt('mac', short='M', val="MAC",
+gopts.opt('mac', short='M', val="MAC",
          fn=append_value, default=[],
          use="""Add a network interface with the given mac address to the domain.
          More than one interface may be specified. Interfaces with unspecified MAC addresses
          are allocated a random address.""")
 
-opts.opt('nics', val="N",
+gopts.opt('nics', val="N",
          fn=set_int, default=1,
          use="Set the number of network interfaces.")
 
-opts.opt('vnet', val='VNET',
+gopts.opt('vnet', val='VNET',
          fn=append_value, default=[],
          use="""Define the vnets for the network interfaces.
          More than one vnet may be given, they are used in order.
          """)
 
-opts.opt('root', short='R', val='DEVICE',
+gopts.opt('root', short='R', val='DEVICE',
          fn=set_value, default='',
          use="""Set the root= parameter on the kernel command line.
          Use a device, e.g. /dev/sda1, or /dev/nfs for NFS root.""")
 
-opts.opt('extra', short='E', val="ARGS",
+gopts.opt('extra', short='E', val="ARGS",
          fn=set_value, default='',
          use="Set extra arguments to append to the kernel command line.")
 
-opts.opt('ip', short='I', val='IPADDR',
+gopts.opt('ip', short='I', val='IPADDR',
          fn=set_value, default='',
          use="Set the kernel IP interface address.")
 
-opts.opt('gateway', val="IPADDR",
+gopts.opt('gateway', val="IPADDR",
          fn=set_value, default='',
          use="Set kernel IP gateway.")
 
-opts.opt('netmask', val="MASK",
+gopts.opt('netmask', val="MASK",
          fn=set_value, default = '',
          use="Set kernel IP netmask.")
 
-opts.opt('hostname', val="NAME",
+gopts.opt('hostname', val="NAME",
          fn=set_value, default='',
          use="Set kernel IP hostname.")
 
-opts.opt('interface', val="INTF",
+gopts.opt('interface', val="INTF",
          fn=set_value, default="eth0",
          use="Set the kernel IP interface name.")
 
-opts.opt('dhcp', val="off|dhcp",
+gopts.opt('dhcp', val="off|dhcp",
          fn=set_value, default='off',
          use="Set kernel dhcp option.")
 
-opts.opt('nfs_server', val="IPADDR",
+gopts.opt('nfs_server', val="IPADDR",
          fn=set_value, default=None,
          use="Set the address of the NFS server for NFS root.")
 
-opts.opt('nfs_root', val="PATH",
+gopts.opt('nfs_root', val="PATH",
          fn=set_value, default=None,
          use="Set the path of the root NFS directory.")
 
@@ -160,7 +161,7 @@ def make_config(opts):
         config_image.append(['ip', cmdline_ip])
     if opts.root:
         cmdline_root = strip('root=', opts.root)
-        config_image.append(['root', opts.root])
+        config_image.append(['root', cmdline_root])
     if opts.extra:
         config_image.append(['args', opts.extra])
     config.append(['image', config_image ])
@@ -221,7 +222,9 @@ def preprocess_pci(opts):
         d = v.split(',')
         if len(d) != 3:
             opts.err('Invalid pci specifier: ' + v)
-        pci.append(d)
+        # Components are in hex: add hex specifier.
+        hexd = map(lambda v: '0x'+v, d)
+        pci.append(hexd)
     opts.pci = pci
 
 def preprocess_ip(opts):
@@ -247,6 +250,8 @@ def preprocess_nfs(opts):
     opts.extra = nfs + ' ' + opts.extra
     
 def preprocess(opts):
+    if not opts.kernel:
+        opts.err("No kernel specified")
     preprocess_disk(opts)
     preprocess_pci(opts)
     preprocess_ip(opts)
@@ -278,6 +283,7 @@ def make_domain(opts, config):
     return (dom, console_port)
 
 def main(argv):
+    opts = gopts
     args = opts.parse(argv)
     if opts.config:
         pass
@@ -285,6 +291,7 @@ def main(argv):
         opts.load_defaults()
     if opts.help:
         opts.usage()
+        return
     preprocess(opts)
     config = make_config(opts)
     if opts.dryrun:
index 4c70717521961709475cfca6a346e4cfc47214e7..ebd9411428a8f0d3811a755462b21a7394af5bb6 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
-import string
 import sys
 
+from xenmgr import PrettyPrint
 from xenmgr import sxp
 from xenmgr.XendClient import server
 from xenmgr.xm import create, shutdown
@@ -39,7 +39,7 @@ class Xm:
     def help(self, meth, args):
         name = meth[3:]
         f = getattr(self, meth)
-        print "%s\t%s" % (name, f.__doc__ or '')
+        print "%-14s %s" % (name, f.__doc__ or '')
 
     def xm_help(self, help, args):
         """Print help."""
@@ -69,11 +69,12 @@ class Xm:
             print args[0], "FILE"
             print "\nRestore a domain from FILE."
         if len(args) < 2: self.err("%s: Missing file" % args[0])
-        server.xend_domain_restore(dom, None, filename)
+        filename = args[1]
+        server.xend_domain_restore(None, filename)
 
-    def xm_ls(self, help, args):
+    def xm_domains(self, help, args):
         """List domains."""
-        if help: self.help('xm_' + args[0]); return
+        if help: self.help('xm_' + args[0], args); return
         doms = server.xend_domains()
         print 'Dom  Name             Mem(MB)  CPU  State  Time(s)'
         for dom in doms:
@@ -87,6 +88,18 @@ class Xm:
             d['cpu_time'] = float(sxp.child_value(info, 'cpu_time', '0'))
             print ("%(dom)-4d %(name)-16s %(mem)4d     %(cpu)3d %(state)5s %(cpu_time)10.2f" % d)
 
+    def xm_domain(self, help, args):
+        """Get information about a domain."""
+        if help:
+            print args[0], 'DOM'
+            print '\nGet information about domain DOM.'
+            return
+        if len(args) < 2: self.err("%s: Missing domain" % args[0])
+        dom = args[1]
+        info = server.xend_domain(dom)
+        PrettyPrint.prettyprint(info)
+        print
+
     def xm_halt(self, help, args):
         """Terminate a domain immediately."""
         if help:
@@ -101,8 +114,8 @@ class Xm:
         """Shutdown a domain."""
         shutdown.main(args)
 
-    def xm_stop(self, help, args):
-        """Stop execution of a domain."""
+    def xm_pause(self, help, args):
+        """Pause execution of a domain."""
         if help:
             print args[0], 'DOM'
             print '\nStop execution of domain DOM.'
@@ -111,11 +124,11 @@ class Xm:
         dom = args[1]
         server.xend_domain_stop(dom)
 
-    def xm_start(self, help, args):
-        """Start execution of a domain."""
+    def xm_unpause(self, help, args):
+        """Unpause a paused domain."""
         if help:
             print args[0], 'DOM'
-            print '\nStart execution of domain DOM.'
+            print '\nUnpause execution of domain DOM.'
             return
         if len(args) < 2: self.err("%s: Missing domain" % args[0])
         dom = args[1]
@@ -131,31 +144,31 @@ class Xm:
         v = map(int, args[1:3])
         server.xend_domain_pincpu(*v)
 
-    def xm_vif_stats(self, help, args):
-        """Get stats for a virtual interface."""
-        if help:
-            print args[0], 'DOM VIF'
-            print '\nGet stats for interface VIF on domain DOM.'
-            return
-        if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
-        v = map(int, args[1:3])
-        print server.xend_domain_vif_stats(*v)
-
-    def xm_vif_rate(self, help, args):
-        """Set or get vif rate params."""
-        if help:
-            print args[0], "DOM VIF [BYTES USECS]"
-            print '\nSet or get rate controls for interface VIF on domain DOM.'
-            return
-        n = len(args)
-        if n == 3:
-            v = map(int, args[1:n])
-            print server.xend_domain_vif_scheduler_get(*v)
-        elif n == 5:
-            v = map(int, args[1:n])
-            server.xend_domain_vif_scheduler_set(*v)
-        else:
-            self.err("%s: Invalid argument(s)" % args[0])
+##     def xm_vif_stats(self, help, args):
+##         """Get stats for a virtual interface."""
+##         if help:
+##             print args[0], 'DOM VIF'
+##             print '\nGet stats for interface VIF on domain DOM.'
+##             return
+##         if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
+##         v = map(int, args[1:3])
+##         print server.xend_domain_vif_stats(*v)
+
+##     def xm_vif_rate(self, help, args):
+##         """Set or get vif rate params."""
+##         if help:
+##             print args[0], "DOM VIF [BYTES USECS]"
+##             print '\nSet or get rate controls for interface VIF on domain DOM.'
+##             return
+##         n = len(args)
+##         if n == 3:
+##             v = map(int, args[1:n])
+##             print server.xend_domain_vif_scheduler_get(*v)
+##         elif n == 5:
+##             v = map(int, args[1:n])
+##             server.xend_domain_vif_scheduler_set(*v)
+##         else:
+##             self.err("%s: Invalid argument(s)" % args[0])
 
     def xm_bvt(self, help, args):
         """Set BVT scheduler parameters."""
@@ -193,16 +206,29 @@ class Xm:
             print "\nSet round robin scheduler slice."
             return
         if len(args) != 2: self.err("%s: Invalid argument(s)" % args[0])
-        slice = int(args[1])
-        server.xend_node_rrobin_set(slice)
+        rrslice = int(args[1])
+        server.xend_node_rrobin_set(rrslice)
 
     def xm_info(self, help, args):
         """Get information about the xen host."""
-        if help: self.help('xm_info'); return
+        if help: self.help('xm_' + args[0], args); return
         info = server.xend_node()
         for x in info[1:]:
             print "%-23s:" % x[0], x[1]
 
+    def xm_consoles(self, help, args):
+        """Get information about domain consoles."""
+        if help: self.help('xm_' + args[0], args); return
+        l = server.xend_consoles()
+        print "Dom Port  Id"
+        for x in l:
+            info = server.xend_console(x)
+            d = {}
+            d['dom'] = sxp.child(info, 'dst', ['dst', '?', '?'])[1]
+            d['port'] = sxp.child_value(info, 'port', '?')
+            d['id'] = sxp.child_value(info, 'id', '?')
+            print "%(dom)3s %(port)4s %(id)3s" % d
+
     def xm_console(self, help, args):
         """Open a console to a domain."""
         if help:
index 7b32daeae23aa1775cb5e546ced2aace9fe1e393..426a6d24d1604feaab7a4af058327323ec728a89 100644 (file)
@@ -91,6 +91,7 @@ class Opts:
         self._vals = {}
         self._globals = {}
         self._locals = {}
+        self.quiet = 0
 
     def opt(self, name, **args):
         x = Opt(self, name, **args)
index 805af2929d4cbe7bd7cfd092a6f4853301574579..8c7a517e96d195b17c7b9c38768ccf067ae1165b 100644 (file)
@@ -5,19 +5,19 @@ import time
 from xenmgr.XendClient import server
 from xenmgr.xm.opts import *
 
-opts = Opts(use="""[options] [DOM]
+gopts = Opts(use="""[options] [DOM]
 
 Shutdown one or more domains gracefully.""")
 
-opts.opt('help', short='h',
+gopts.opt('help', short='h',
          fn=set_value, default=0,
          use="Print this help.")
 
-opts.opt('all', short='a',
+gopts.opt('all', short='a',
          fn=set_true, default=0,
          use="Shutdown all domains.")
 
-opts.opt('wait', short='w',
+gopts.opt('wait', short='w',
          fn=set_true, default=0,
          use='Wait for shutdown to complete.')
 
@@ -28,7 +28,7 @@ def shutdown(opts, doms, wait):
     if 0 in doms:
         doms.remove(0)
     for d in doms:
-        server.xend_domain_shutdown(dom)
+        server.xend_domain_shutdown(d)
     if wait:
         while doms:
             alive = domains()
@@ -55,6 +55,7 @@ def main_dom(opts, args):
     shutdown(opts, [ domid ], opts.wait)
     
 def main(argv):
+    opts = gopts
     args = opts.parse(argv)
     if opts.help:
         opts.usage()